package com.miaostars.level.data;

public enum Rank {
    IRON("刚硬铁块", 0, 100, "&7[刚硬铁块]"),
    GOLD("闪闪黄金", 101, 500, "&6[闪闪黄金]"),
    REDSTONE("不朽红石", 501, 1500, "&c[不朽红石]"),
    DIAMOND("耀眼钻石", 1501, 4000, "&b[耀眼钻石]"),
    ALLOY("超级合金", 4001, Integer.MAX_VALUE, "&e[超级合金]");

    public static Rank fromStats(PlayerStats stats) {
        int exp = calculateExp(stats);
        for (Rank rank : values()) {
            if (exp >= rank.minExp && exp <= rank.maxExp) return rank;
        }
        return IRON;
    }

    private static int calculateExp(PlayerStats stats) {
        double penalty = 1.0 - (stats.getDeaths() * 0.05); // 死亡惩罚
        return (int) (stats.getKills() * (1 + Math.min(stats.getCps(), 20) * 0.3) * penalty);
    }
}